package com.snailct.bpp.service.client.factory;

import com.snailct.bpp.commons.exception.ErrorCode;
import com.snailct.bpp.commons.utils.PropertiesUtil;
import com.snailct.bpp.service.client.ClientException;
import com.snailct.bpp.service.client.IServiceInvoker;
import com.snailct.bpp.service.client.support.HttpServiceInvoker;
import com.snailct.bpp.service.client.support.SpringServiceInvoker;
import com.snailct.bpp.service.client.support.WSServiceInvoker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 客户端调用服务入口API
 * Created by huangxa on 2016/7/26.
 */
public abstract class ServiceInvokerFactory {
    private static final Log logger = LogFactory.getLog(ServiceInvokerFactory.class);
    private enum InvokerFactoryError{
        @ErrorCode(comment = "Not support invoke type[${1}]")
        NOT_SUPPORT_TYPE
    }
    private enum InvokerType{
        WS,
        HTTP,
        SPRING
    }
    public static IServiceInvoker getServiceInvoker(){
        String invokerType = PropertiesUtil.getPropValue("invokerType");
        if(InvokerType.WS.name().equals(invokerType)){
            logger.warn("InvokerType is null.Use Web Service invoker!");
            return new WSServiceInvoker();
        }
        else if(InvokerType.HTTP.name().equals(invokerType)){
            //http请求
            return new HttpServiceInvoker();
        }else if(InvokerType.SPRING.name().equals(invokerType)){
            return new SpringServiceInvoker();
        }else{
            throw new ClientException(InvokerFactoryError.NOT_SUPPORT_TYPE,invokerType);
        }
    }
}
